package com.mo.star.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mo.star.pojo.Message;
import com.mo.star.pojo.User;
import com.mo.star.service.MessageService;
import com.mo.star.mapper.MessageMapper;
import com.mo.star.vo.ChatCard;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 云赋
 * @description 针对表【message(消息实体表)】的数据库操作Service实现
 * @createDate 2024-09-06 11:38:13
 */
@Service
@Log4j
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message>
        implements MessageService {
    @Resource
    MessageMapper messageMapper;
    @Resource
    UsertableServiceImpl userService;
@Override
    public List<ChatCard> seChatCart(HttpServletRequest request){
        User loginUser = userService.getLoginUser(request);
        if(loginUser ==null)
            return null;
        String loginUserId = loginUser.getId();
        return messageMapper.seChatCart(loginUserId);
    }
    @Override
    public List<Message> messageList(String fromUserId, String toUserId){

        return  messageMapper.messageList(fromUserId,toUserId);
    }
    @Override
    public int doMessage(Message message){
    return messageMapper.doMessage(message);
    }
    @Override
    public int doChat(String fromUserId, String toUserId){
        int i1 = messageMapper.dochat(fromUserId,toUserId);
        int i2 = messageMapper.dochat(toUserId,fromUserId);
        return i1+i2;
    }

}




